﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
using System.IO;

/// <summary>
/// Summary description for ServiceBase
/// </summary>
[Serializable]
public class ServiceBase
{
	public ServiceBase()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public string SerializeToString()
    {
        XmlSerializer serializer = new XmlSerializer(this.GetType());

        using (StringWriter writer = new StringWriter())
        {
            serializer.Serialize(writer, this);

            return writer.ToString();

        }
    }

    public static object CreateFromString<T>(string value)
    {
        try
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));

            using (StringReader reader = new StringReader(value))
            {
                object o = serializer.Deserialize(reader);
                return o;
            }
        }
        catch
        {
            return null;
        }
    }
}